package com.example.function.integration.service.impl;

import com.example.function.integration.exception.BizException;
import com.example.function.integration.service.FunctionTestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @Description：
 * @Author： fengcheng
 * @Date： 2024/10/12 11:00
 */
@Slf4j
@Service
public class FunctionTestServiceImpl implements FunctionTestService {

    @Override
    public Boolean testGlobalException() {
        // 测试全局异常捕获，抛出BizException类型异常
        try {
            int i = 1 / 0;
        } catch (Exception e) {
            log.error("测试全局异常-这里会捕获到这个业务异常 - " + e.getMessage(), e);
            throw new BizException("当前业务处理发生异常！");
        }
        // 测试全局异常捕获，抛出RuntimeException类型异常
        try {
            int i = 1 / 0;
        } catch (RuntimeException e) {
            log.error("测试全局异常-这里会捕获到这个运行时异常 - " + e.getMessage(), e);
            throw new RuntimeException("测试全局异常-这里会捕获到这个运行时异常！");
        }
        // 测试全局异常捕获，抛出NullPointerException类型异常
        try {
            Object obj = null;
            obj.toString();
        } catch (NullPointerException e) {
            log.error("测试全局异常-这里会捕获到这个空指针异常 - " + e.getMessage(), e);
            throw new NullPointerException("业务处理发生空指针异常！");
        }
        return true;
    }
}
